package com.doublefish.doublefishrobot.ui.video.bean;

import android.content.Context;
import android.text.TextUtils;

import com.doublefish.doublefishrobot.utils.AppCacheUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者:dugaofeng on 2024/10/28 08:50
 */
public class VideoInfoBean {

    //本地数据库id
    private int t_id;

    private String code;  //01R02
    private String name;
    private boolean isHD; //是否高清视频

    //本地是否存在视频  0.无  1.下载中 2.暂停下载  99.已下载完毕
    private int isExistVideo;
    //版本
    private String ver;
    //时长
    private float time;
    //视频大小
    private long size;

    //远程视频地址的播放/下载地址
    private String url;
    //本地视频的地址
    private String localPath;
    //远程视频下载到本地的临时缓存地址
    private String tempPath;

    private String desc;


    public int getTid() {
        return t_id;
    }

    public void setTid(int t_id) {
        this.t_id = t_id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    /**
     2025-7-24 为了针对多语言适配，又不想改动数据库。
     用一个折中的办法，直接重写getter方法
     */
    public String getName() {
//        return name;

        Context context = AppCacheUtil.getInstance().getAppContext();
        // 动态获取字符串资源
        String keyName = String.format("mode_%s", code);
        int resId = context.getResources().getIdentifier(keyName, "string", context.getPackageName());
        if (resId != 0) {
            return context.getString(resId);
        } else {
            return "";
        }
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isHD() {
        return isHD;
    }

    public void setIsHD(boolean isHD) {
        this.isHD = isHD;
    }

    public int getIsExistVideo() {
        return isExistVideo;
    }

    public void setIsExistVideo(int isExistVideo) {
        this.isExistVideo = isExistVideo;
    }

    public String getVer() {
        return ver;
    }

    public void setVer(String ver) {
        this.ver = ver;
    }

    public float getTime() {
        return time;
    }

    public void setTime(float time) {
        this.time = time;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getLocalPath() {
        return localPath;
    }

    public void setLocalPath(String localPath) {
        this.localPath = localPath;
    }

    public String getTempPath() {
        return tempPath;
    }

    public void setTempPath(String tempPath) {
        this.tempPath = tempPath;
    }

    /**
     2025-7-24 为了针对多语言适配，又不想改动数据库。
     用一个折中的办法，直接重写getter方法
     */
    public String getDesc() {
//        return desc;

        Context context = AppCacheUtil.getInstance().getAppContext();
        // 动态获取字符串资源
        String keyName = String.format("desc_%s", code);
        int resId = context.getResources().getIdentifier(keyName, "string", context.getPackageName());
        if (resId != 0) {
            return context.getString(resId);
        } else {
            return "";
        }
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String fileSizeText() {
        long kb = size / 1024;  //转为kb
        if (kb > 1024) {
            long mb = kb / 1024;
            return  mb + "MB";
        } else {
            return kb + "KB";
        }
    }



    public Map<String, Object> toDataBaseMap() {
        Map map = new HashMap();
        if (t_id > 0 ) {
            map.put("t_id", t_id);
        }
        if (!TextUtils.isEmpty(name)) {
            map.put("name", name);
        }
        if (!TextUtils.isEmpty(code)) {
            map.put("code", code);
        }
        map.put("isHD", isHD ? 1 : 0);
        map.put("isExistVideo", isExistVideo);
        if (!TextUtils.isEmpty(ver)) {
            map.put("ver", ver);
        }
        map.put("time", time);
        map.put("size", size);
        if (!TextUtils.isEmpty(ver)) {
            map.put("ver", ver);
        }
        if (!TextUtils.isEmpty(url)) {
            map.put("url", url);
        }
        if (!TextUtils.isEmpty(localPath)) {
            map.put("localPath", localPath);
        }
        if (!TextUtils.isEmpty(tempPath)) {
            map.put("tempPath", tempPath);
        }
        if (!TextUtils.isEmpty(desc)) {
            map.put("desc", desc);
        }
        return map;
    }
}
